import time
import unittest

from parameterized import parameterized

from automatic.base.get_driver import GetDriver
from automatic.base.get_logger import GetLogger
from automatic.page.page_login import PageLogin
from automatic.tools.read_text import read_txt
from automatic.page.page_task_team import PageTaskTeam


# 获取log 日志器
log = GetLogger().get_logger()


def get_data():
    arrs = []
    for data in read_txt("task_team.txt"):
        arrs.append(tuple(data.strip().split(",")))
    return arrs[1:]


# 新建 新建任务测试类 并 继承 unittest.TestCase
class TestTaskTeam(unittest.TestCase):
    # 新建setUpClass
    @classmethod
    def setUpClass(cls) -> None:
        try:
            # 实例化 并 获取 driver
            cls.driver = GetDriver.get_driver()
            # 实例化PageLogin(),调用登录功能
            cls.login = PageLogin(cls.driver)
            # 执行登录操作
            cls.login.page_login_success()
            #实例化PageTaskTeam
            cls.task_team=PageTaskTeam(cls.driver)
            #调用方法，进入标注团队目录
            cls.task_team.page_click_all_team()
            time.sleep(2)

        except Exception as e:
            # 截图
            cls.task_team.base_get_img()
            # 日志
            log.error("错误：{}".format(e))

    # 新建tearDownClass
    @classmethod
    def tearDownClass(cls) -> None:
        # 关闭driver驱动对象
        GetDriver.quit_driver()

    # @parameterized.expand(get_data())
    # def test_add_user(self):
    #     try:
    #         self.task_team.add_user_success()
    #         msg=self.task_team.page_get_info()
    #         print(msg)
    #         try:
    #             self.assertEqual(msg,"用户")
    #         except Exception as e:
    #             # 截图
    #             self.task_team.base_get_img()
    #             # 日志
    #             log.error("添加用户测试失败：{}".format(e))
    #
    #     except Exception as e:
    #         # 截图
    #         self.task_team.base_get_img()
    #         # 日志
    #         log.error("出错了：{}".format(e))

    # @parameterized.expand(get_data())
    # def test_add_user_err(self):
    #     try:
    #         self.task_team.page_click_add_user()
    #         time.sleep(2)
    #         self.task_team.page_click_confirm()
    #         msg=[]
    #         for i in range(1,5):
    #             msg.append(self.task_team.page_get_add_err_info(i))
    #         print(msg)
    #         try:
    #             self.assertEqual(msg[0],"请输入用户名")
    #             self.assertEqual(msg[1],"请输入密码")
    #             self.assertEqual(msg[2],"请再次输入密码")
    #             self.assertEqual(msg[3],"请选择标注团队")
    #         except Exception as e:
    #             # 截图
    #             self.task_team.base_get_img()
    #             # 日志
    #             log.error("添加用户测试失败：{}".format(e))
    #
    #     except Exception as e:
    #         # 截图
    #         self.task_team.base_get_img()
    #         # 日志
    #         log.error("出错了：{}".format(e))



    # @parameterized.expand(get_data())
    # def test_add_team_err(self):
    #     try:
    #         self.task_team.page_click_add_team()
    #         time.sleep(2)
    #         self.task_team.page_click_confirm()
    #         msg=self.task_team.page_get_err_info()
    #         print(msg)
    #         try:
    #             self.assertEqual(msg,"请输入团队名称")
    #         except Exception as e:
    #             # 截图
    #             self.task_team.base_get_img()
    #             # 日志
    #             log.error("添加团队测试失败：{}".format(e))
    #
    #     except Exception as e:
    #         # 截图
    #         self.task_team.base_get_img()
    #         # 日志
    #         log.error("出错了：{}".format(e))


    # def test_edit_team_success(self):
    #     try:
    #         self.task_team.edit_team_success()
    #         msg=self.task_team.page_get_info()
    #         print(msg)
    #         try:
    #             self.assertEqual(msg,"提交成功")
    #         except Exception as e:
    #             # 截图
    #             self.task_team.base_get_img()
    #             # 日志
    #             log.error("编辑团队测试失败：{}".format(e))
    #
    #     except Exception as e:
    #         # 截图
    #         self.task_team.base_get_img()
    #         # 日志
    #         log.error("出错了：{}".format(e))


    def test_edit_members(self):
        try:
            self.task_team.edit_user_member('cxx2')
            msg=self.task_team.page_get_info()
            print(msg)
            try:
                self.assertEqual(msg,"复制成功")
            except Exception as e:
                # 截图
                self.task_team.base_get_img()
                # 日志
                log.error("编辑成员测试失败：{}".format(e))

        except Exception as e:
            # 截图
            self.task_team.base_get_img()
            # 日志
            log.error("出错了：{}".format(e))


if __name__ == '__main__':
    unittest.main()
